#include "HumanMethodMove.h"
#include "GameActivity.h"
#include "ChessBoard.h"
#include "GameRule.h"
#include <vector>
#include <iostream>

HumanMethodMove::HumanMethodMove()
{
}

void HumanMethodMove::doChess(ChessBoard * chessBoard, GameRule * gameRule, Player * player){
    QPoint position;
    QPoint movePosition;
    std::vector<QPoint>* qPointList = new std::vector<QPoint>;

    while(!GameActivity::isEnd && !gameRule->checkChosenPoint(position = chessBoard->getPosition(),player));
    if(GameActivity::isEnd)
        return;
    while(1){
        emit updateUI();
        chessBoard->getChess(position)->setAttribute("chosen","true");
        std::cout<<player->getSide()<<": "<<position.x()<<" "<<position.y()<<std::endl;
        movePosition = chessBoard->getPosition();
        std::cout<<player->getSide()<<": "<<movePosition.x()<<" "<<movePosition.y()<<std::endl;
        if(GameActivity::isEnd)
            return;
        else if(gameRule->checkChosenPoint(movePosition,player)){
            chessBoard->getChess(position)->setAttribute("chosen","false");
            position = movePosition;
            chessBoard->getChess(movePosition)->setAttribute("chosen","true");
            continue;
        }
        else{
            if(gameRule->checkAddPoint(position,movePosition,player)){
                chessBoard->getChess(position)->setAttribute("chosen","false");
                break;
            }
        }
    }

    qPointList->push_back(position);
    qPointList->push_back(movePosition);
    gameRule->putChess(qPointList,player);

}
